using System.Collections;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;

public class Lesson14 : MonoBehaviour
{
    Thread t;
    Queue<int> queue = new Queue<int>();
    // Start is called before the first frame update
    
    IEnumerator MyCorotine(int i,string name)
    {
        //print("1");
        //yield return new WaitForSeconds(5f);
        //print("6");
        while(true)
        {
            print(name + ":" + i);
            yield return new WaitForSeconds(1f);
            i++;
        }
    }
    void Start()
    {
        t = new Thread(test);
       // t.Start();
       IEnumerator i1=MyCorotine(1,"123");
       IEnumerator i2=MyCorotine(1,"123");
       IEnumerator i3=MyCorotine(1,"123");
        StartCoroutine(i1);
        StartCoroutine(i2);
        StartCoroutine(i3);
        //StopAllCoroutines();
        StopCoroutine(i3);
    }

    // Update is called once per frame
    void Update()
    {
        if(queue.Count>0)
        {
            int q=queue.Dequeue();
            print(q);
            
        }
        
    }
    void test()
    {
        while (true)
        {
            Thread.Sleep(1000);
            queue.Enqueue(1);
        }
    }

    private void OnDestroy()
    {
        t.Abort();
        t= null;    
    }
}
